﻿<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Samcrypt"
	x:Class="Samcrypt.MainWindow"
	x:Name="Window"
	Title="{Binding Path=Name}"
	Width="714" Height="506" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Closing="Window_Closing">

    <Window.Resources>
        <Style x:Key="statusBarItemStyle" TargetType="{x:Type StatusBarItem}">
            <Setter Property="Control.Padding" Value="3"/>
            <Setter Property="Panel.Background" Value="#00FFFFFF"/>
            <Setter Property="Control.HorizontalAlignment" Value="Left"/>
            <Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
            <Setter Property="Control.VerticalContentAlignment" Value="Center"/>
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type StatusBarItem}">
                        <Border
                            BorderThickness="0,0,1,1"
                            BorderBrush="#FFFFFFFF"
                            Background="{TemplateBinding Panel.Background}"
                            SnapsToDevicePixels="True">
                            <Border
                                BorderThickness="1,1,0,0"
                                Padding="{TemplateBinding Control.Padding}"
                                BorderBrush="#FFACAB99"
                                Background="#FFECEBDE"
                                SnapsToDevicePixels="True">
                                <ContentPresenter
                                    Content="{TemplateBinding ContentControl.Content}"
                                    ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                    HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                    SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </Border>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="UIElement.IsEnabled" Value="False">
                                <Setter
                                    Property="TextElement.Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Window.InputBindings>
        <KeyBinding Key="n" Modifiers="Control" Command="{x:Static local:SamcryptCommands.NewPage}" />
        <KeyBinding Key="o" Modifiers="Control" Command="ApplicationCommands.Open" />
        <KeyBinding Key="s" Modifiers="Control" Command="ApplicationCommands.Save" />

        <KeyBinding Key="c" Modifiers="Alt" Command="{x:Static local:SamcryptCommands.SaveToClipboard}" />
        <KeyBinding Key="v" Modifiers="Alt" Command="{x:Static local:SamcryptCommands.OpenFromClipboard}" />
    </Window.InputBindings>

    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.New" Executed="CmdExecuted" />
        <CommandBinding Command="ApplicationCommands.Open" Executed="CmdExecuted" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="CmdExecuted" />
        <CommandBinding Command="ApplicationCommands.SaveAs" Executed="CmdExecuted" />

        <CommandBinding Command="{x:Static local:SamcryptCommands.SaveToClipboard}" Executed="CmdExecuted" />
        <CommandBinding Command="{x:Static local:SamcryptCommands.OpenFromClipboard}" Executed="CmdExecuted" />

        <CommandBinding Command="{x:Static local:SamcryptCommands.NewPage}" Executed="CmdExecuted" />
        <CommandBinding Command="{x:Static local:SamcryptCommands.DeletePage}" Executed="CmdExecuted" />

    </Window.CommandBindings>


    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Menu HorizontalAlignment="Stretch" Width="Auto" VerticalAlignment="Top" Height="Auto">
            <MenuItem Header="File">
                <MenuItem Header="Change Password..." IsEnabled="False" />
                <Separator />
                <MenuItem Header="Open from clipboard" Command="{x:Static local:SamcryptCommands.OpenFromClipboard}" />
                <MenuItem Header="Save to clipbaord" Command="{x:Static local:SamcryptCommands.SaveToClipboard}" />
                <Separator />
                <MenuItem Header="New" Command="ApplicationCommands.New" />
                <MenuItem Header="Open..." Command="ApplicationCommands.Open" />
                <MenuItem Header="Save" Command="ApplicationCommands.Save" />
                <MenuItem Header="Save As..." Command="ApplicationCommands.SaveAs" />
                <Separator />

                <MenuItem Header="Exit" IsEnabled="False" />
            </MenuItem>
            <MenuItem Header="Help" IsEnabled="False"/>
        </Menu>

        <ToolBarTray  HorizontalAlignment="Stretch" Grid.Row="1" >

            <ToolBar Name="ButtonBar" >
                <!--<Button Margin="2,0" Padding="8,0" Name="newButton"  Command="ApplicationCommands.New">New</Button>-->
                <Button Margin="2,0" Padding="8,0" Name="openButton" Command="ApplicationCommands.Open">Open</Button>
                <Button Margin="2,0" Padding="8,0" Name="saveButton" Command="ApplicationCommands.Save">Save</Button>

            </ToolBar>

            <ToolBar>
                <TextBlock VerticalAlignment="Center" Margin="5,0">Password:</TextBlock>
                <PasswordBox Name="passwordBox" Width="100"></PasswordBox>
            </ToolBar>

            <ToolBar Name="Mixed">

                <Label Margin="0,0" Content="Scale:" />
                <Slider Name="scaleSlider" Width="100" Minimum="1" Maximum="4" Value="1"  />

                <Label Margin="5,0,0,0" Content="Font Size:" />
                <Slider Name="fontSlider" Width="100" Minimum="8" Maximum="34" Value="15"  />
            </ToolBar>

        </ToolBarTray>


        <!-- <TextBox  x:Name="mainText" Grid.Row="2" FontSize="{Binding ElementName=fontSlider, Path=Value}" FontFamily="Courier New"
                  Text="{Binding Path=Text}" AcceptsTab="True"
                  AcceptsReturn="True" TextWrapping="NoWrap"
                  HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" TextChanged="mainText_TextChanged"
                  SpellCheck.IsEnabled="{Binding ElementName=spellingCheckBox, Path=IsChecked}" >
            
            
            <TextBox.LayoutTransform>
                <ScaleTransform ScaleX="{Binding ElementName=scaleSlider, Path=Value}" ScaleY="{Binding ElementName=scaleSlider, Path=Value}" />
                
            </TextBox.LayoutTransform>
            
        </TextBox>-->

        <Grid Name="docUIGrid" Grid.Row="2">

            <Grid.LayoutTransform>
                <ScaleTransform ScaleX="{Binding ElementName=scaleSlider, Path=Value}" ScaleY="{Binding ElementName=scaleSlider, Path=Value}" />
            </Grid.LayoutTransform>


            <Grid.Resources>
                


                <Style x:Key="newPageButtonStyle1" TargetType="{x:Type Button}">

                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border x:Name="buttonBorder" CornerRadius="0,7,7,0" BorderBrush="Black" BorderThickness="0,1,1,1" HorizontalAlignment="Stretch" Margin="0,0,0,0">
                                    <Border.Background>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Offset="0" Color="#F7F7F7"/>
                                            <GradientStop Offset="1" Color="#CFDDE7"/>
                                            <!--<GradientStop Offset="0" Color="LightGray"/>
                                            <GradientStop Offset="1.5" Color="DarkGreen"/>-->
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <ContentPresenter Margin="4"  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <!--<Trigger Property="IsKeyboardFocused" Value="true">
								<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
							</Trigger>-->
                                    <Trigger Property="Button.IsMouseOver" Value="true">
                                        <!--<Setter Property="Border.BorderBrush" TargetName="buttonBorder">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,1" EndPoint="0,0">
                                            <GradientStop Offset="0" Color="#FFD42A"/>
                                            <GradientStop Offset="1" Color="#FFAA2A"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>-->
                                    </Trigger>

                                    <Trigger Property="Button.IsPressed" Value="true">
                                        <Trigger.Setters>
                                            <!--<Setter Property="Border.BorderBrush" TargetName="buttonBorder">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                <GradientStop Offset="0" Color="#FFD42A"/>
                                                <GradientStop Offset="1" Color="#FFAA2A"/>
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>-->
                                            <Setter Property="TextBlock.Foreground" Value="#696969" />
                                            <Setter Property="Control.Background" TargetName="buttonBorder">
                                                <Setter.Value>
                                                    <LinearGradientBrush StartPoint="0,1" EndPoint="0,0">
                                                        <GradientStop Offset="0" Color="AliceBlue"/>
                                                        <GradientStop Offset="1" Color="#CFDDE7"/>
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>

                                        </Trigger.Setters>
                                    </Trigger>
                                    <!--<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Foreground" Value="#ADADAD"/>
							</Trigger>-->
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>




            </Grid.Resources>


            <Border Name="outerBorder" Padding="7" BorderBrush="DarkGray" BorderThickness="0,1,0,1" 
                Background="{StaticResource outerBackground}"  >

                <Grid Name="mainGrid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"  />
                        <ColumnDefinition Width="100" 
                                      MaxWidth="{Binding ElementName=mainGrid, Path=ActualWidth}"
                                      MinWidth="13"/>
                    </Grid.ColumnDefinitions>

                    <Border Name="documentBorder" Grid.Row="0" BorderBrush="Black" BorderThickness="1">

                        <Grid Name="documentGrid" Grid.Column="0">

                            <Grid.RowDefinitions>
                                <RowDefinition Height="60" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Border Name="docHeaderBorder" Grid.Row="0" BorderBrush="Black" BorderThickness="0,0,0,1"
                                Background="{StaticResource docHeaderBackground}">


                                <Grid Name="docHeaderGrid"  >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition  Width="3*" MaxWidth="275" />

                                        <ColumnDefinition Width="2*" />
                                    </Grid.ColumnDefinitions>

                                    <Border Name="docTitleBorder" Grid.Column="0" VerticalAlignment="Center"  Padding="4,0,4,1" Margin="15,0,6,0"  
                                           
                                        Style="{StaticResource docTitleBorderStyle1}"
                                        >
                                        <TextBox x:Name="textBox2"  FontSize="17"  Background="Transparent" BorderBrush="Transparent"
                                                 DataContext="{Binding Path=Document.Pages}"
                                                 Text="{Binding Path=Title, UpdateSourceTrigger=PropertyChanged}" 
                                                 SpellCheck.IsEnabled="{Binding ElementName=spellingCheckBox, Path=IsChecked}"
                                                 />
                                    </Border>

                                    <StackPanel Name="docDateTimePanel" Grid.Column="2" 
                                            VerticalAlignment="Center"  HorizontalAlignment="Right"
                                            >
                                        <TextBlock Margin="0,4,15,0" 
                                               DataContext="{Binding Path=Document.Pages}"
                                               Text="{Binding Path=LastModifed, 
                                               Converter={StaticResource formatter}, ConverterParameter=' \{0:MMMM d, yyyy\}'}" 
                                               Style="{StaticResource docDateTimeStyle1}"/>
                                        <TextBlock Margin="0,0,15,0" 
                                               DataContext="{Binding Path=Document.Pages}"
                                               Text="{Binding Path=LastModifed, 
                                               Converter={StaticResource formatter}, ConverterParameter=' \{0:h:mm tt\}'}"
                                               Style="{StaticResource docDateTimeStyle1}"/>
                                    </StackPanel>
                                </Grid>

                            </Border>

                            <TextBox x:Name="docBodyTextBox" Grid.Row="1" AcceptsReturn="True" 
                                     VerticalScrollBarVisibility="Visible"  
                                     HorizontalScrollBarVisibility="Auto"
                                 Margin="1,0,0,0"
                                    DataContext="{Binding Path=Document.Pages}"
                                    Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}"
                                 
                                 TextWrapping="NoWrap"
                                 FontSize="{Binding ElementName=fontSlider, Path=Value}" FontFamily="Courier New"
                                 SpellCheck.IsEnabled="{Binding ElementName=spellingCheckBox, Path=IsChecked}"
                                     
                                 
                                 TextChanged="docBodyTextBox_TextChanged">

                            </TextBox>

                            <GridSplitter Name="docHeaderSplitter" Grid.Row="0" Background="Transparent" Height="3" 
                                      HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />

                        </Grid>

                    </Border>


                    <Grid Name="pageTabsGrid" Grid.Column="1" VerticalAlignment="Top" >

                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <ListBox  x:Name="pageTabsListBox" SelectionChanged="pageTabsListBox_SelectionChanged" 
                              Margin="-2,5,0,0" BorderThickness="0" Background="Transparent"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" 
                              VerticalAlignment="Top"  ScrollViewer.CanContentScroll="False"
                              
                              DataContext="{Binding Path=Document.Pages}"
                              ItemsSource="{Binding }"
                                  IsSynchronizedWithCurrentItem="True"
                              >
                            <ListBox.Resources>
                                <Style TargetType="ListBoxItem">

                                    <Style.Resources>
                                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                                    </Style.Resources>


                                    <Style.Setters>
                                        <Setter Property="Foreground" Value="Black" />
                                        <Setter Property="Background" Value="{StaticResource docPageTabBackground}" />
                                        <Setter Property="BorderBrush" Value="Black" />
                                        <Setter Property="BorderThickness" Value="1,1,1,1" />
                                        <Setter Property="Margin" Value="0,-1,0,0" />

                                        <Setter Property="Template" >
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                    <Border x:Name="myBorder" CornerRadius="0,7,7,0" HorizontalAlignment="Stretch" 
                                                        Margin="{TemplateBinding Margin}"
                                                        Background="{TemplateBinding Background}"
                                                        BorderBrush="{TemplateBinding BorderBrush}"
                                                        BorderThickness="{TemplateBinding BorderThickness}"
                                                        Padding="{TemplateBinding Padding}"
                                                        SnapsToDevicePixels="true"
                                                         MouseDown="myBorder_MouseDown"
                                                            
                                                            >

                                                        <Border.ContextMenu>
                                                            <ContextMenu>
                                                                <MenuItem x:Name="newPage" Header="New"  Command="{x:Static local:SamcryptCommands.NewPage}" />
                                                                <MenuItem x:Name="deletePage" Header="Delete" Command="{x:Static local:SamcryptCommands.DeletePage}"  />
                                                            </ContextMenu>
                                                        </Border.ContextMenu>

                                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>


                                                    </Border>
                                                </ControlTemplate>

                                            </Setter.Value>
                                        </Setter>

                                    </Style.Setters>

                                    <Style.Triggers>


                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter Property="Foreground" Value="Black" />
                                            <Setter Property="Border.BorderThickness" Value="0,1,1,1" />
                                            <Setter Property="Padding" Value="3,0,0,0"  />


                                            <Setter Property="Background" Value="{StaticResource docPageTabSelectedBackground}" />
                                        </Trigger>


                                        <DataTrigger Binding="{Binding Path=VM.IsFirst}" Value="True">
                                            <Setter Property="Border.Margin" Value="0,0,0,0" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>



                            </ListBox.Resources>


                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock FontSize="11" TextAlignment="Left" VerticalAlignment="Center" Margin="4" TextTrimming="CharacterEllipsis" 
                                               Text="{Binding Path=Title, UpdateSourceTrigger=PropertyChanged}" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>

                        </ListBox>

                        <Button x:Name="newPageButton" Grid.Row="1" VerticalAlignment="Top" FontSize="11" Margin="0,6,15,7" 
                            Command="{x:Static local:SamcryptCommands.NewPage}" Style="{DynamicResource newPageButtonStyle1}" Content="New"  />

                    </Grid>



                    <GridSplitter Grid.Column="1" HorizontalAlignment="Left"  Grid.Row="0" Grid.RowSpan="2" Width="3" Background="Transparent" 
                                Height="Auto" 
                                VerticalAlignment="Stretch" />

                </Grid>
            </Border>

        </Grid>


        <StatusBar HorizontalAlignment="Stretch" Width="Auto" Grid.Row="3" VerticalAlignment="Bottom" >
            <StatusBarItem>
                <Border BorderThickness="1" BorderBrush="LightGray"  CornerRadius="5" Padding="10,0">
                    <Label Content="{Binding Path=VersionString}" />
                </Border>
            </StatusBarItem>

            <StatusBarItem>
                <Border BorderThickness="1" BorderBrush="LightGray"  CornerRadius="5" Width="60" >
                    <Label Content="{Binding Path=Document.DirtyText}" HorizontalAlignment="Center"  />
                </Border>
            </StatusBarItem>

            <StatusBarItem>
                <Border BorderThickness="1" BorderBrush="LightGray"  CornerRadius="5" Padding="15,5" >


                    <CheckBox VerticalAlignment="Center" Name="spellingCheckBox" Content="Spell Check"/>



                </Border>
            </StatusBarItem>

        </StatusBar>


    </Grid>
</Window>